import time


class StopWatch:

    def __init__(self):
        self.acts = ['start']
        t = time.time()
        self.ts = [t]

    def stop(self, act='stop'):
        self.acts.append(act)
        t = time.time()
        self.ts.append(t)

    def clear(self):
        self.acts = ['start']
        t = time.time()
        self.ts = [t]

    def __str__(self):
        assert len(self.acts) == len(self.ts)
        to_disp = ['StopWatch [\n']
        for i, a, t in zip(range(1, len(self.acts)), self.acts[1:], self.ts[1:]):
            elapsed = t - self.ts[i - 1]
            to_disp.append(f'{i:4d} ACT {a:32} ELAPSED {elapsed:7.3f} sec\n')
        to_disp.append(']')
        return ''.join(to_disp)
